/**
 * 测试规则: TryStatement
 * 来源: 从 Statement 拆分
 */

/* Es2025Parser.ts: try Block (Catch | Finally | Catch Finally) */

/**
 * 规则测试：TryStatement
 * 
 * 位置：Es2025Parser.ts Line 1288
 * 分类：statements
 * 编号：419
 * 
 * 规则语法：
 *   TryStatement:
 *     try Block Catch
 *     try Block Finally
 *     try Block Catch Finally
 * 
 * 测试目标：
 * - 覆盖try-catch、try-finally、try-catch-finally
 * - 验证catch参数和finally执行
 * - 覆盖各种异常处理场景
 * 
 * 创建时间：2025-11-01
 * 状态：✅ 已完善
 */

// ✅ 测试1：基本try-catch
try {
    console.log('try')
} catch (e) {
    console.log('error')
}

// ✅ 测试2：try-finally（无catch）
try {
    console.log('try')
} finally {
    console.log('finally')
}

// ✅ 测试3：try-catch-finally（完整）
try {
    console.log('try')
} catch (e) {
    console.log('catch')
} finally {
    console.log('finally')
}

// ✅ 测试4：throw异常
try {
    throw new Error('test error')
} catch (e) {
    console.log(e.message)
}

// ✅ 测试5：自定义Error对象
try {
    throw { code: 'CUSTOM', msg: 'custom error' }
} catch (err) {
    console.log(err.code)
}

// ✅ 测试6：catch中的异常处理
try {
    throw new Error('first')
} catch (e) {
    try {
        throw new Error('second')
    } catch (e2) {
        console.log(e2.message)
    }
}

// ✅ 测试7：finally中的代码保证执行
let finally_executed = false
try {
    throw new Error('test')
} catch (e) {
    console.log('caught')
} finally {
    finally_executed = true
}

// ✅ 测试8：try中的return和finally
function tryReturn() {
    try {
        return 'from try'
    } finally {
        console.log('in finally')
    }
}

// ✅ 测试9：catch中的return和finally
function catchReturn() {
    try {
        throw new Error('error')
    } catch (e) {
        return 'from catch'
    } finally {
        console.log('in finally')
    }
}

// ✅ 测试10：嵌套try-catch
try {
    try {
        throw new Error('inner error')
    } catch (e) {
        console.log('inner catch')
        throw new Error('rethrow')
    }
} catch (e) {
    console.log('outer catch')
}

// ✅ 测试11：try-catch中的循环
try {
    for (let i = 0; i < 5; i++) {
        if (i === 3) throw new Error('at 3')
        console.log(i)
    }
} catch (e) {
    console.log('loop error')
}

// ✅ 测试12：try中的函数调用
function mayThrow() {
    throw new Error('function error')
}
try {
    mayThrow()
} catch (e) {
    console.log('caught function error')
}

// ✅ 测试13：finally中的异常
try {
    console.log('try')
} finally {
    throw new Error('finally error')
}

// ✅ 测试14：复杂异常处理
try {
    const obj = null
    console.log(obj.property)
} catch (e) {
    if (e instanceof TypeError) {
        console.log('type error')
    } else {
        console.log('other error')
    }
} finally {
    console.log('cleanup')
}

// ✅ 测试15：完整异常处理场景
function processData(data) {
    try {
        if (!data) throw new Error('No data')
        const result = JSON.parse(data)
        return result
    } catch (e) {
        console.log('Parse error: ' + e.message)
        return null
    } finally {
        console.log('Done processing')
    }
}

/* Es2025Parser.ts: TryStatement: try Block (Catch | Finally | Catch Finally) */
